home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / nihcl-30.lha / nihcl-3.0 / ex / Shape.h < prev    next >
C/C++ Source or Header  |  1990-05-15  |  1KB  |  46 lines

  1. #ifndef SHAPE_H
  2. #define SHAPE_H
  3.  
  4. // Shape.h -- Abstract geometric shape class
  5.  
  6. // $Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/ex/RCS/Shape.h,v 3.0 90/05/15 22:44:05 kgorlen Rel $
  7.  
  8. #include "Object.h"
  9. #include "Point.h"
  10. #include "Stack.h"
  11.  
  12. class Shape: public Object {
  13.     DECLARE_MEMBERS(Shape);
  14.     Point org;          // origin
  15. protected:              // storer() functions for object I/O
  16.     virtual void storer(OIOofd&) const;
  17.     virtual void storer(OIOout&) const;
  18. protected:
  19.     Shape(const Point& p) : org(p)  {}
  20. public:
  21.     Point origin() const                { return org; }
  22.     virtual void move(const Point& d)   { org += d; }
  23.     virtual void draw() const = 0;
  24.     virtual void deepenShallowCopy();
  25.     virtual unsigned hash() const = 0;
  26.     virtual bool isEqual(const Object&) const = 0;
  27.     virtual void printOn(ostream& strm =cout) const = 0;
  28.     virtual const Class* species() const;
  29. private:                // shouldNotImplement()
  30.     virtual int compare(const Object&) const;
  31. };
  32.  
  33. class TransformStack {
  34. public:
  35.     static TransformStack transform;    // shape translation stack
  36. private:
  37.     Stack s;
  38. public:
  39.     TransformStack()        { s.push(*new Point(0,0)); }
  40.     Point* current() const  { return (Point*)s.top(); }
  41.     void push(Point& p)     { s.push(*new Point(*current() + p)); }
  42.     void pop()              { delete (Point*)s.pop(); }
  43. };
  44.  
  45. #endif
  46.